#ifndef E_CONTROLLER_QT_PROPERTY_H
#define E_CONTROLLER_QT_PROPERTY_H

#include "EItem.h"
#include "EItemMetaProperty.h"
#include "qtreewidget.h"
#include <DefineLibCommon.h>
#include <DefineCommon.h>
#include <cstdint>
#include <memory>

#include <EController.h>
#include <WidgetBox/WidgetBox.h>
#include <WidgetVariant.h>

/**This class is
 * */
class EControllerQtProperty;
typedef SmartPtr(EControllerQtProperty) EControllerQtPropertyPtr;
class EControllerQtProperty : public QObject, public EController
{
    Q_OBJECT
public:
    EControllerQtProperty();
    virtual ~EControllerQtProperty();

    void setWidgetBox(WidgetBox* w);

    /*clear TreeWidget and loop all children and build Tree Item*/
    virtual void refresh();

    /*overwrite EItemVisitor's core function*/
    virtual bool handleEItem(EItemPtr item, int depth, EItemPtr parentItem);

    /*handle*/
    virtual void handleCommand(const ECommandPtr& command);
    virtual void handleCommandSelectItem(const ECommandPtr& command);
    virtual void handleCommandPropertyUndo(const ECommandPtr& command);
    virtual void handleCommandPropertyRedo(const ECommandPtr& command);
    virtual void handleCommandPropertyChangedByOther(const ECommandPtr& command);

    /*new WidgetVariant according to property's data*/
    WidgetVariant* convertPropertyToWidget(EItemMetaPropertyPtr p);
    
public slots:
    void slotVariantChanged(EItemMetaPropertyPtr p, EVariant oldValue );

protected:
    WidgetBox* m_widgetBox;

    EItemPtr m_itemPtr;

    QMap<long, WidgetVariant*> m_mapTag2WidgetVariant;
    QMap<long, EItemMetaPropertyPtr> m_mapTag2Property;
    QMap<long, EItemMetaFunctionPtr> m_mapTag2Function;
};

#endif // E_CONTROLLER_QT_PROPERTY_H
